#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=1e9+7,inf=0x3f3f3f3f3f3f3f3f;
int fp(int x,int p)
{
	int ans=1;
	while(p--)ans*=x;
	return ans;
}
void solve()
{
	int a,b,c,ans=0;
	cin >>a >>b>>c;
	for ( int i = 1 ; i <= a ; i++ )
	{
		for ( int j = 1 ; j <= b ; j++ )
		{
			for ( int k = 1 ; k <= c ; k++ )
			{
				if(fp(i,j)==fp(j,k))ans++;
			}
		}
	}
	cout << ans%mod<<endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("alien.in","r",stdin);
	freopen("alien.out","w",stdout);
	int T;
	cin >>T;
	while(T--)solve();
	return 0;
}//5

